package com.itheima.info.manager.service;

import com.itheima.info.manager.dao.BaseTeacherDao;
import com.itheima.info.manager.domain.Teacher;
import com.itheima.info.manager.factroy.SystemFactory;

import java.util.ArrayList;

public class TeacherService {
    BaseTeacherDao teacherDao = SystemFactory.getTeacherDao();

    //判断学号是否存在
    public  boolean isExits(String id) {
        ArrayList<Teacher> list;
        list = teacherDao.findAllTeacher();
        Teacher teacher = new Teacher();
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            teacher = list.get(i);
            if (teacher != null && teacher.getId().equals(id)){
                flag = true;
                break;
            }
        }
        return flag;
    }
    //添加老师
    public void addTeacher(Teacher teacher) {
        teacherDao.addTeacher(teacher);
    }
    //查看老师
    public ArrayList findAllTeacher() {
        ArrayList<Teacher> allTeacher = teacherDao.findAllTeacher();
        if (allTeacher == null){
            return null;
        }else {
            return allTeacher;
        }
    }
    //删除老师
    public void deleteTeacherById(String id) {
        teacherDao.deleteTeacher(id);
    }
    //修改老师
    public void updateTeacher(String id, Teacher teacher) {
        teacherDao.updateTeacher(id,teacher);
    }
}
